import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import com.mysql.jdbc.PreparedStatement;

public class loginService {

	public Boolean checkLogin(String user, String pas) throws Exception{
		Connection con = null;
		try{
			Class.forName("com.mysql.jdbc.Driver");
			con = DriverManager.getConnection("jdbc:mysql://localhost:8889/licenseDb","root", "root");

			PreparedStatement query = (PreparedStatement) con.prepareStatement("select * from Logins where emailAddress=? and password=?");
			query.setString(1, user);
			query.setString(2, pas);
			ResultSet rs = query.executeQuery();
			rs.last();
			Integer rowCount = rs.getRow();
			if (rowCount==1){
				System.out.println("Autentificare valida!");
				return true;
			}
		}
		catch (Exception e){
			System.out.println(e.getMessage());
		}
		finally{
			try {
				if(con != null)
					con.close();
			} catch(Exception e) {}
		}
		System.out.println("Autentificare esuata!");
		return false;
	}

	public static void main (String[] args) throws Exception{
		loginService user = new loginService();
		user.checkLogin("luci_ionutz_88@yahoo.com", "triliard123");
	}
}
